Sec 3 2016 2
Sec 3 2016 2
Loops
Jump
While loop Do while For loop Nested loop
statements.
Simple example:
3: do while Loops
Simple example:
4: for Loops
Simple example:
5: Nested Loops
Simple example:
Output
6: Jump statements.
Ex:
B: The continue statement
The continue statement causes the program to skip the rest of the loop in the current iteration
as if the end of the statement block had been reached, causing it to jump to the start of the
following iteration. For example, we are going to skip the number 5 in our countdown:
Ex:
C: The go to statement
go to allows to make an absolute jump to another point in the program. You should use this
feature with caution since its execution causes an unconditional jump ignoring any type of
nesting limitations. The destination point is identified by a label, which is then used as an
argument for the go to statement. A label is made of a valid identifier followed by a colon (:).
EX:
Programmers:
Pro 1
suppose you have the task of producing a Celsius-to- Fahrenheit temperature
conversion table. Fahrenheit temperatures corresponding to Celsius temperatures
from 5 to 50 degrees are to be displayed in increments of 5 degrees
Code:
Por 2
Calculate the Product of two numbers WITHOUT using the * operator
Code:
Output
Pro 3
Counting a’s (or any character), we want to read a text represented as a sequence
of characters, we want to calculate the number of occurrences of the
letter, we can assume that the text always has at least one
character
Example: the text
ayman and ahmed are working in commerce.
Now notice that we have 5 a's
Code:
Output
Pro 4
Data is requested and accepted continuously until a number larger than 100 is
entered. Entry of a number higher than 100 alerts the program to exit the while
loop and display the sum of the numbers entered.
Sol 1:
Output
Sol2 using break:
Code
Output
Pro 6
Write c++ program to computes the positive and negative sums of a set of
MAXNUMS user-entered numbers.
Code:
Output
Pro 7
Write c++ program to compute the average grade for each student in a class of 20
students. Each student has taken four exams during the semester. The final grade
is calculated as the average of these exam grades.
Code:
Output:
Pro 8
Develop an C++ program to print the prime numbers that included between 1
and 100.
Code:
Output
Assignment
Code:
a,
Output: a