0% found this document useful (0 votes)
4 views1 page

Variable and Loop Algorithms Guide

The document outlines the structure and algorithms for creating variables, outputting messages, and implementing loops in programming. It details the initialization of variables, the process for user input, and the mechanics of both for and while loops. Each section provides a clear algorithmic approach for handling data and control flow in a program.

Uploaded by

EDWIN THUNGARI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Variable and Loop Algorithms Guide

The document outlines the structure and algorithms for creating variables, outputting messages, and implementing loops in programming. It details the initialization of variables, the process for user input, and the mechanics of both for and while loops. Each section provides a clear algorithmic approach for handling data and control flow in a program.

Uploaded by

EDWIN THUNGARI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

New variable

- Name: what do we call this thing?


- Type: what type of data does it contain?
- InitVal: what is it’s starting value?
- New variable algorithm
o Create a variable called name of type
o Type that starts with the value initVal

Output
- Message: text to write to user
- Output algorithm
o Output the text message
Input
- Variable: where answer from user will be stored
- Message: question being asked of the user
- Input algorithm
o Ask the user message and store the answer in variable
For loop
- Sentry: integer variable that will control loop
- Start: integer value of sentry at beginning
- Finish: integer value of sentry at end
- Change: integer to add to sentry at each pass
- For algorithm
o Begin with sentry at start and add
o Change to sentry on each pass until
o Sentry is larger than or equal to finish

While loop
- Sentry: variable that will control loop
- Initialization code: code that initializes sentry
- Condition: loop repeats if condition is true
- Change code: code to change sentry so condition can be triggered
- While loop algorithm
o Initialize sentry with initialization code
o Then continue loop as long as condition is
o True. Inside loop, change sentry with
o Change code

You might also like