cs31 lecture 17

X syntax while condition instructions instructions x

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: endl; std::cout x Some properties: The <init> statement is executed only once, and can contain The variable declarations variable The <test> is executed at each iteration, including the first one. The The loop iterates while this test is true The The <test> can be an arbitrarily complex expression that can be The converted to int 44 More examples x Example: multiple initializations: for (int i = 1, j = 2; j <= 10 && i < 100; i++)
 x Example: multiple increments: Example: for (int i = 1, j = 2; j <= 10 && i < 100; i++, j++)
 for x Example: infinite loop: Example: for (int i = 1, j = 2; ; i++, j++)
 for 45 While loops x Straightforward adapting from algorithmic language! x Syntax: while (<condition>)
 <instructions> <instructions> x Example: while (i < 10)
 std::cout << i << std::endl; std::cout 46 Do loops x Straightforward adapting from algorithmic language! x Syntax: do <instructions> <instructions> while (<condition>)
 x Example: do std::cout << i << std::endl; std::cout while (i < 10)
 47 A reminder about blocks of instructions x A block of more than one instruction is encapsulated in block { and } and Example: { std::cout << i << std::endl; std::cout i = i + 1; 1; } x In loops in C++, <instructions> is either a single In instruction, or a block of instructions encapsulated in { } instruction, 48 Constants x Definition: a constant...
View Full Document

This note was uploaded on 04/03/2014 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.

Ask a homework question - tutors are online