M1 - Lecture C1 Ada overview Response to'Muddiest Part of the Lecture Cards(17 respondents out of 60 1 I still don't understand nested loops(1

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture C1: Ada overview Response to 'Muddiest Part of the Lecture Cards' (17 respondents out of 60) 1) I still don't understand nested loops (1 student) Statements within a loop statement can be built up of arbitrary statements, thus there may well be one loop statement within another. This is a very common construct to use in programs. A small example: We want to write a triangle of stars (*) on the screen. The first row will have 1 star, the second row will have 2 stars, …, and the Nth row will have N stars. N will be read as input from the terminal. So, if N = 4 then the output will be * ** *** **** Algorithm: 1. Read in number N 2. Repeat the following step for each number K,from 1 to N. 2.1 print a row of K stars Step 1: Put_Line ( "enter the number of rows to be printed" ); Get(N); Step 2: for K in 1 ..N loop -- 2.1 print a row of K stars end loop ; Step 2.1 for J in 1 ..K loop Put( '*' ); end loop ; New_Line; All put together: with Ada.Text_Io, ada.Integer_Text_IO; use Ada.Text_Io, ada.Integer_Text_IO; procedure Nested_Loops is N : integer; begin Put_Line ( "enter the number of rows to be printed" ); Get(N);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
for K in 1 ..N loop for J in 1 ..K
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/28/2012 for the course AERO 16.01 taught by Professor Markdrela during the Fall '05 term at MIT.

Page1 / 3

M1 - Lecture C1 Ada overview Response to'Muddiest Part of the Lecture Cards(17 respondents out of 60 1 I still don't understand nested loops(1

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online