facebook rss daftar isi halaman depan

Laman

Sabtu, 06 November 2010

bahasa pascal

Control structures

Statements for building control structures are roughly analogous and relatively similar (at least the first three).

Pascal has:

* if cond then stmt else stmt
* while cond do stmt
* repeat stmt until cond
* for id := expr to expr do stmt and for id := expr downto expr do stmt
* case expr of expr : stmt; ... expr : stmt; else: stmt; end

C has:

* if (cond) stmt else stmt
* while (cond) stmt
* do stmt while (cond)
* for (expr; cond; expr) stmt
* switch (expr) { case expr : stmt; ... case expr : stmt; default: stmt }

Pascal, in its original form, did not have an equivalent to default, but an equivalent else clause is a common extension. Pascal programmers otherwise had to guard case-statements with an expression such as: if expr not in [A..B] then default-case.

C has the so called early-out statements break and continue, and some Pascals have them as well. There is controversy about whether the inclusion of these statements is in keeping with structured programming methodology. The best that can be said about this is that the use of break and continue may make programming easier, but there is no case where they cannot be replaced by "orthodox" structured programming constructs.

Both C and Pascal have a goto statement. However, since Pascal has nested procedures/functions, jumps can be done from an inner procedure or function to the containing one; this was commonly used to implement error recovery. C has this capability via the ANSI C setjmp and longjmp. This is equivalent, but arguably less safe, since it stores program specific information like jump addresses and stack frames in a programmer accessible structure.

Tidak ada komentar:

Posting Komentar

terimakasih aras kunjungan anda di blog mesujiraya
komentarnya saya tunggu mas bro & mbak sist