Ok Just Using Free Day Pass Mane - School Of Finesse - Okay

1598 words - 7 pages

CSCI 135
Control Flow (Selection)
Basic Language Constructs
Recall: each statement in an imperative language updates the
value of some variable.
⇒ Classes of Constructs:
Declaration of variables: How does the variable map onto
Updating variable: How do we update the variable, and what
do we update it with?
I/O: How do we input and output data into the system?
Control: How do we control which statement gets executed
Modularity and Object Orientation: How do we organize the
program to enable proper software engineering practices?
Comments: Used to describe code; ignored by compiler, but
code unmaintainable without good comments!
C/C++: on line beginning with // or surrounded by /*, */
Types of Control
Selection: Execute a different instruction depending on the
result of evaluating some [Boolean] condition.
if/else, multiway if, switch, ? :
Iteration: Repetitively execute some instruction until some
condition is met,
for, while, do while
Goto: Execute some instruction (not necessarily the next one)
A Absolutely, NEVER never never use this (See Dijkstra,
“Go To Statement Considered Harmful”); leads to
unmaintainable spaghetti code.
Break: Leave block
A condition is a Boolean expression - i.e., one that evaluates to
true or false.
Most commonly either a relational operator or a logical
combination of conditions:
Relational (Comparison) Operators: == != < > <= >=
(semantics vary by type of operands)
Logical operators: ! && ||
Note: conjuncts/disjuncts are evaluated left-to-right and only
if needed (called short-circuit evaluation)
See Fig. 2.3 for precedence order (but better to use parentheses)
BEquality (==) is not the same as assignment (=).
BRecent versions of C++ support alternate syntaxes for logical
operators (e.g., “and”). Avoid these as they are rarely used (and
not compatible with earlier C/C++ standards).
Conditions - Examples
n <= 100 && n >= 0
n < 101 && n >= 0
grade > ’c’ && grade <= ’f’
y < x && y >= 0
?© Which points of the Cartesian plane does this cover?
!s.empty() && (s[0] == ’f’ || s[0] == ’g’)
?© Why does the order of conjuncts matter?
Short-Circuit Evaluation
Almost all languages: left-to-right, completely
C/C++ Special Cases: &&, ||, ?
Evaluate the 2nd operand only if it can change the result of
the expression; i.e., short-circuit the evaluation. Ex:
Don’t evaluate Q in P && Q if P evaluates to false
Don’t evaluate Q in P || Q if P evaluates to true
Similarly for ?
⇒ useful when evaluating the Q would lead to an error for the
’wrong’ case of P
Ex: !s.empty() && (s[0] . . .)
Caveat: Conditions in C
A C condition actually evaluates to an integer (not a true-false
bool). If the integer is 0, it is interpreted as false; otherwise it is
interpreted as true.
Normally, you don’t need to worry about this (phew!). BUT
?© What would if (n=5) S1 else S2 do if n is initially 2?
Caveat: Conditions in C
A C condition actually evaluates to an integer (not a true-false
bool). If the integer is 0, it is interpreted as false; otherwise it is
interpreted as true.
Normally, you don’t need to worry about this (phew!). BUT
?© What would if (n=5) S1 else S2 do if n is initially 2?
1 Evaluate the condition n=5, which is actually an assignment
statement/expression that stores 5 in n and evaluates to the
rval (5)
2 Since 56=0, interpret it as true
3 Execute S1
BConfusing = and == is a very common source of bugs!
& vs &&
& Bit-wise and operator
&& Logical and operator, produces 1 iff both operands are true
(non-zero), and 0 otherwise.
x = 1 ; y=2;
z = x & y ; evaluates to 0
z = x && y ; evaluates to 1
(similarly for | vs ||)
Selection: If/else
if S1 else S2
(commonly called if/then, though C doesn’t use keyword then)
Execute S1 if cond evaluates to true, and S2 otherwise, where
S1/S2 are statements.
(else S2 is optional)
i f ( h r s < 40)
pay = r a t e ∗ h r s ; indent block
e l s e { start of compound statement
pay = r a t e ∗40 + 1.5∗ r a t e ∗( hrs −40);
pay = pay − f t d e d ; // deduc t i on f o r f u l l t i m e r s
} ; end of compound statement
// December bonus f o r a l l
i f (month==12) pay=pay ∗ 1 . 1 ; no else case here
BGood practice (not practiced above): use {} even if block has
only one statement
Selection with Multiple Conditions
i f ( h r s < 10)
{ . . . }
e l s e
i f ( h r s < 15) // [ 1 0 , 1 4 ] hour s
{ . . . }
e l s e
i f ( h r s < 20) // [ 1 5 , 1 9 ] hour s
{ . . . }
e l s e
i f ( h r s < 30) // [ 2 0 , 2 9 ] hour s
{ . . . }
e l s e // >30 hours
{ . . . }
⇒ Indentation is a nightmare!
Multiway If-Else
Better solution:
i f ( h r s < 10)
{ . . . }
e l s e i f ( h r s < 15) // [ 1 0 , 1 4 ] hour s
{ . . . }
e l s e i f ( h r s < 20) // [ 1 5 , 1 9 ] hour s
{ . . . }
e l s e i f ( h r s < 30) // [ 2 0 , 2 9 ] hour s
{ . . . }
e l s e // >30 hours
{ . . . }
Not a new construct, just a different (better) indentation style
Selection with Many Cases
A statement for controlling multiple (> 2) branches
Condition must be based on some expression that evaluates to
an integral value (all types of int, char, some others)
Can do the same with if statements, but switch may be more
convenient and readable
Especially useful for ’menus’ (one case for each menu option)
Selection: Switch
switch ( e xp r ) {
case v a l 1 :
s tmt 1 executed if expr evaluates to val1
break ; exit [entire] switch statement
case v a l 2 :
s tmt 2
break ;
. . .
case v a l n
s tmt n
break ;
defau l t : executed if none of above cases applied
d e f a u l t s tm t
Expr must be integral
Without break, control goes through the next case (common error
to omit break, but sometimes useful)
Switch Example
char t e s t G r a d e ;
sw i t ch ( t e s t G r a d e ) {
case ’ a ’ :
cout << ” C o n g r a t u l a t i o n s ! ” ;
break ; prevents next message from being printed
case ’ b ’ :
cout << ” Jus t a l i t t l e more work needed ” ;
break ;
case ’ c ’ :
cout << ”Need to work h a r d e r ! ” ;
break ;
case ’ d ’ : no break; falls through to next case
case ’ f ’ :
cout << ”Not good ” ;
break ;
d e f a u l t : don’t forget the ’error’ case!
cout << ” E r r o r : u n r e c o g n i z e d grade ” ;
} ;
cout << e n d l ; after switch; done in all cases
Selection: Conditional
Shorthand for [typically] 1-line if-else
i f (m > n )
max = m;
e l s e
max = n ;
≡ max = (m > n ) ? m : n ;
Also called ternary operator
Good for quick one-liner, but can be misused:
?© What does this do? (a

More like Ok Just Using Free Day Pass Mane - School Of Finesse - Okay

Memour Of My First Day Of School For Creative Writing Class - Silvestri Creative Writing - Essay

1489 words - 6 pages ... first day at a new school. I expected nothing more than a jolt of anxiety, but instead i came intense dread. I haven't been to a school since December before i got my tonsils out on the 12th. Let alone that this school had 1,800 students in a grade, and i came from Avonworth let’s keep in mind. I didn’t know what to expect, It was January and I was just now starting school here. So many frightening possibilities came into my mind as I sat up in bed ...

An Analysis Of A Day At School In Kyrgyzstan - IDS 333 - Analysis Assignment

560 words - 3 pages ... Maya Bellamy Brandi Neal IDS 13 September 2018 Close Reading A Day at School in Kyrgyzstan is a short story that sums up one day, from start to finish, in this particular country. Author, and teacher, Kathryn Hulick expresses her thoughts and emotions while dealing with such strong-willed students. She begins by setting the tone of the writing by describing the time of day as well as the weather. By emphasizing her “gigantic” coat, hat and scarf ...

This Is A Poem I Wrote About The Every Day Life Of High School Students. Enjoy

485 words - 2 pages ... school runs.Fourth period comes,And students' stomachs are rumbling;No luck for them in their studies,Despite all their grumblingAt last, lunch arrives, and three dollars will be goneIf its pizza this day that students hope to feed on.Laughing and eating are now a norm,Much like the atmosphere of a college dormFifth period is quiet,And deadly as well,As an after lunch napCould mean for your grade ... not well.Now, dear comrades, the battle is over,And after six periods of torture have come and goneOur daily afternoon lives will go on ...

Some Of Them Are Good From Them You Get Lessons. - HIGH SCHOOL - ESSAY

550 words - 3 pages ... played a lot of games at friends house.We went to a park near his house and also went to play golf.We danced all the day and enjoyed that day a lot.At 3pm, we left his house. After all the day, when I returned home, my dad asked me how was the day in school and what you learn today? I said it was good but as the time passes I felt guilty that I deceive my dad who is working hard just to make me happy and to make my dreams true.He have a dream ...

Racism Sexism And Religion. Still Big Issues For America

725 words - 3 pages ... other race is treated better than their race. Between blacks and whites it is just nuts, I never owned a slave and no black person I know was a slave, GET OVER IT! I think America has set itself up to be the land of the free and the home of the brave. Send us your poor and hungry and we will take care of them. But, the way America behaves is like a teenager on their first day of a new job. America pretends like it is ok with everything that goes ...

A Challenging Year; About My High School Life In Myanmar. - Florida International University - Essay

1047 words - 5 pages Free ... A Challenging Year That day was my first day of 9th grade. I transferred to a new private school. I looked at the clock and it was 9 o’ clock. I was late. I just washed my face, brushed my teeth and wore the uniform which is like a crisp and as clean-cut as a blue sky of the deepest summer. As the soft material brushed over my face, I could almost taste the meadows of pure cotton. My dad took me to the school and he repeatedly yelled at me like ...

Imma Land Castle Rock And Get A Hunti Ryfle Then Hit A Phat Nosc On Ur Glidng Ass - University Of Milk And Obesity - Essay

500 words - 2 pages ... : communication lesson (importance of team communication and example drills, how it helps to beat defences and offences) 20 Hour 16: Tournament to reassess ability in movement knowledge and communication. 22 Hour 17: in depth analysis of importance and proper use of off ball movements to score. 27 Hour 18: analysis of travelling rule (two steps and jump is ok if shot is made before landing or pass is made before landing, or it’s a travel.) 4 Hour ...

Revenge Essay

919 words - 4 pages ... It feels like it was just yesterday that I got revenge on my friend. He deserved what I did to him. How he just took my bike without my permission and ruined my bike. Then he acts like everything is okay and nothing had happened. It really felt great to get him back. The way that he walked away in anger and the expression on his face. He looked like he was going to cry. I didn't care though. He never did repay me for my bike. Yeah ok so im ...

Should Welfare Involve Drug Testing? - Ohio University; English 1010 - Argument Paper

937 words - 4 pages ... Argument Essay The world changes every day. More people are born, more jobs collapse, and more opportunities present themselves. Government is such a powerful aspect of our lives, and there is not much we can do about it. The government seems as if it is beginning to take over and control our lives. Telling us what we can and cannot eat, how to treat others, and how to raise our children. These are parts of life that are meant to be decided upon ...

A Story Of An Imaginary Friend Coming To Life - Year 9 English - Creative Writing

1397 words - 6 pages ... You know that feeling of a presence behind you? the calm breathing on the back of your neck? the small sounds of footsteps behind you? the chills you get on your back? the floorboards creaking?   I walk into my room after coming back from an exhausting day of school. All of a sudden, the temperature drops. My body is overcome by fear. I feel an unusual presence behind me. All the hairs on my back spike up. My heart races. I take a deep breath. 3 ...

Cell Phones Editorial

560 words - 3 pages ... on silent and they are hidden from other classmates! Just two years ago in October a girl took the case to the Supreme Court! She had had her cell phone taken away. It was in her backpack turned off not disturbing anyone when the teacher saw it and took it away and she never had it returned to her! "I wasn't even using it and the teacher saw it in my backpack and confiscated it!" I tried to explain that I had to have it for later that day when ...

Mama And The Boarder Main Points - University Of Hawaii At Manoa - Korean Literature

670 words - 3 pages ... disapproval. Indeed, during this time period in which this story was written, certain rules were placed upon wives whose husbands pass away. It was part of the Korean culture to assume a widow had a sickness or possessed something in which that person could no longer marry another man again. 2. As the readers continue to analyze the story, they are able to depict certain key character traits that Ok-hui possesses. Within the story, there are many ...

The Crossroad's One Faces In Everyday Life English Essay - English - Essay

829 words - 4 pages ... Intersections He crosses the road, still trying to figure out how to navigate the town he’s called home for some two years now. There is never much to do here, the most exciting thing that happens usually being an ambulance or police car wailing down the street. But there are always these beautiful tall green trees anywhere you look, and it’s reasonably peaceful. Dressed purposely to impress his friends on the first day of high school, he wears ...

Process Of Becoming A Civil Engineer - ENG102 - Essay

852 words - 4 pages ... audience. Which I have a wide latitude of independent judgment and self-perseverance to make sure a project gets done. In order for me to become an engineer and move up the ranks to Chief Engineer I need to take three major steps: I need to earn a bachelor’s degree in Civil Engineering at a college with an Accreditation Board for Engineering and Technology (ABET) approved program. Pass my licensing exam, either the Fundamentals of Engineering ...

Human Development - Creative Story - New Zealand Management Academies - Human Development

2301 words - 10 pages ... see me!” Lola’s mother giggled, reminiscing about her first day at high school. “Ok Ok I get it Lola, no one can see us, quickly jump out. Have a great day hunny.” she kissed Lola on the cheek as she jumped out of the car and made her way to work. Lola took a deep breath and walked up the stairs of her new high school. There were people everywhere. She had gone from being the tallest and oldest kid at junior school, to the youngest and shortest ...