Sequential Structures N 201 Introduction to Programming Concepts







- Slides: 7

Sequential Structures N 201 Introduction to Programming Concepts Dept. of Computer and Information Science

Goals • Understand why a sequence structure is used • How to create sequence structure

Sequential Logic • Early programs used sequential logic. That is, Step A happened before Step B happened before Step C, etc. • Sequential programs are easy to write, but lack flexibility. (decisions and loops)

Sequential Structures • A series of statements – Executed in order • No branching – A jump in the flow of execution

Sequential Structures § Start – where the program begins § Input – data to be used for the program § Step One, Step Two, etc. – the sequence of the program until it finishes § No deviation

Sequential Statements • Welcome Message • Ask for data – Input name, address, city, favorite color data • Output data – Write name, address, city, favorite color message

Sequential Structures var str. User. Name = ""; // user's name, this is a STRING var str. User. City = ""; // user's city, this is a STRING var int. Num. Letters = 0; // number of letters in user's first name, this is an INTEGER var str. Message = "" // output to the user, this is a STRING str. User. Name = window. prompt("What is your name? "); //this is asking for the user's name str. User. City = window. prompt("Where do you live? "); //this is asking what city does the user live in str. Message = ("Hello, "); str. Message += (str. User. Name. to. Upper. Case()); //this puts the user's name into uppercase letters str. Message += (". You live in "); str. Message += (str. User. City. to. Upper. Case()); //this puts the user's city into uppercase letters window. alert(str. Message); //this is the message given to the user int. Num. Letters = str. User. Name. length; // output to the user window. alert("There are " +int. Num. Letters+" letters in your first name. "); //this is a string method, it is counting the number of letters in the user's name //this tells the user how many letters that user has in their name