Mapa mental
Control Structures
Contenido del mapa
Control Structures
A control structure is a block of programming that analyzes variables and chooses a direction in which to go based on given parameters. Flow control determines how a computer will respond when given certain conditions and parameters.
As
- IF THEN
- IF variable is true THEN take this course of action.
- If the variable indeed holds a value consistent with being true, then the course of action is taken. If the variable is not true, then there is no course of action taken.
- IF variable is true THEN take this course of action.
- IF THEN ELSE
- IF variable is true THEN take this course of action ELSE call another routine
- If the variable is true, it takes a certain course of action and completely skips the ELSE clause. If the variable is false, the control structure calls a routine and completely skips the THEN clause.
- IF variable is true THEN take this course of action ELSE call another routine
- While & Do-While Loops
- A WHILE loop is a process in which a loop is initiated until a condition has been met. This structure is useful when performing iterative instructions to satisfy a certain parameter.
- Precondition: variable X is equal to 1 WHILE X is not equal to 9 Add 1 to X
- A DO-WHILE loop is nearly the exact opposite to a WHILE loop. A WHILE loop initially checks to see if the parameters have been satisfied before executing an instruction. A DO-WHILE loop executes the instruction before checking the parameters.
- DO Add 1 to X WHILE X is not equal 9
- A WHILE loop is a process in which a loop is initiated until a condition has been met. This structure is useful when performing iterative instructions to satisfy a certain parameter.
- For Loops
- A FOR loop is an extension of a while loop. A for loop usually has three commands. The first is used to set a starting point (like x = 0). The second is the end condition (same as in a while loop) and is run every round. The third is also run every round and is usually used to modify a value used in the condition block.
- FOR X is 0. X is less than 10. add 1 to X.
- This loop would be run 10 times (x being 0 to 9) so you won't have to think about the X variable in the loop you can just put code there.
- FOR X is 0. X is less than 10. add 1 to X.
- A FOR loop is an extension of a while loop. A for loop usually has three commands. The first is used to set a starting point (like x = 0). The second is the end condition (same as in a while loop) and is run every round. The third is also run every round and is usually used to modify a value used in the condition block.
- IF THEN
Example using traffic flow as a model.
- A vehicle is arriving at an intersection. Thus, the precondition is the vehicle is in motion. Suppose the traffic light at the intersection is red. The control structure must determine the proper course of action to assign to the vehicle.
- Precondition: The vehicle is in motion.
- Treatments of Information through Control Structures: -Is the traffic light green? If so, then the vehicle may stay in motion. -Is the traffic light red? If so, then the vehicle must stop.
- End of Treatment
- Postcondition: The vehicle comes to a stop.
- End of Treatment
- Treatments of Information through Control Structures: -Is the traffic light green? If so, then the vehicle may stay in motion. -Is the traffic light red? If so, then the vehicle must stop.
- Precondition: The vehicle is in motion.
- A vehicle is arriving at an intersection. Thus, the precondition is the vehicle is in motion. Suppose the traffic light at the intersection is red. The control structure must determine the proper course of action to assign to the vehicle.
Información
- Descripción
- Mapa Mental sobre Control Structures, creado por Ramón Cordova el 20/02/2019.
- Creado por
- Ramón Cordova
- Visitas
- 0
- Valoración