1 / 9100%
Flow control statements allow a programmer to check conditions
and based on the results of the program. If there is a
problem in code and goes to that certain line of code,
but if the code runs true it will repeatedly keep running.
Also through flow control statements you can use break and
continue statements to continue an iteration and terminate it.
The good thing about C# is it can modularize code into
manageable chunks and complex code can be executed through
C#. A great example of C# being used is when college
students are trying to get admitted into college like text
scores, financial standing and GPA. Where C# comes into play
is colleges run out of space and they have limited financial
aid to give out, having C# would find a loophole and
notify the school if there was space and financial aid available
last minute for a student if another student leaves. It wouldn't
be possible to write software to check various conditions and
change execution paths. Flow control in applications is accomplished
using conditional operators and Booleans to railroad designated
inputs to their ideal outputs. These tools allow for applications
to fulfil a variety of select needs by associating actions on
a user interface to Boolean values which themselves are tied
to actionable code. This conditional code is structured to the
order of its designer provide functionality when needs are met.
The process is multiplied to create an application with a
host of uses. An example application would be a basic match-
3 puzzle game for iOS. The Ui for the app is going
to be “minimalistic”. There’d be a PLAY, OPTIONS, CREDITS,
and “another game I made here” button. All this could be
tied to a branch of “if” statements that proceed to their
corresponding screens. Functions for the game would be tied
to “start”, ”pause”, ”play” and ”share” where when conditionally
read as TRUE would execute their operations allowing the user
to participate in my crafted experience at their own leisure.
Flow control allows for a flow to be controlled. That is
in my eyes a tailored experience that can be operated and
observed by a participant. The concept as applied to programming
applies a level of automation to human interactions that facilitate
end-to-end transactions of all types. Flow control and functions
operate in an application like how the USB symbol looks.
There is a starting point, multiple paths, and the function
calls would represent the tops. The USB symbol resembles this
style of graph that I would use to map out the functions
and flow control. The USB symbol is a great example for
this especially when you put multiple in a graph. The Large
circle would be the starting point, the smaller circle, triangle,
and the square would be the different paths or if statements.
The different tips would be the end of the function but
depending on the point, it would point to or call another
function. Even the paths in the USB could represent paths
in a program, The long triangle would represent the normal
flow and the two sides would be the if statements that
could result in a differing path to another function. I think
that if you were to add two symbols to a graph, it
probably would not work as I would want it to but the
symbol would still be a great representation for flow control
and functions. A good example of a simple weather apps
are the ones found on IOS and Android that provides users
with the current weather conditions, humidity, wind speed, and
a five to seven-day forecast. The main function usually starts
displays the weather and temperature for the day on the
home screen. The apps have the main function call different
sub-functions to display the current weather conditions and the
five to seven-day forecast. Sub-functions are responsible for
retrieving data from an external API, processing the data, and
displaying the results in a user-friendly format.The apps always
allow you to select the user location by using flow control
to prompt the user to enter a location from a list. Once
the location has been selected the app calls a function to
retrieve weather data for that location. When the weather is
displayed, flow control is used to determine how to display
the results based on the user's options selected. Flow control
and functions allow weather apps to be more flexible, modular,
and easier to maintain. It allows developers to reuse code,
reduce redundancy, and make the code easier to understand.
Flow control, on the other hand, creates different paths for
the user to customize the information they wish to have
displayed, making the app more responsive and user-friendly. Flow
control is a basic but very important/powerful concept in
programming. It allows the programmer to have control of how
the lines of code execute and which ones execute. One of
the simplest examples can a discount if a customer purchases
$100 or more of the product. If the purchase is greater
then $100USD, a 10% discount will be given.
Flow Control Example
If the customer bought $100 USD or more in product
((Unit Price X # of
Units) *.9)
If the customer bought less than $100 USD in product
yy yy yy yy yy yy yy Unit Price X # of
Units
Not both of these lines of code will execute. One or the
other and then the appropriate math will be done based on
the purchase price. Flow control allows the code to be more
efficient, maintainable, flexible, and scalable over time. Allowing
the program, the ability to decide which line of code will
be executed next means the code doesn’t have to go line
by line but can skip lines of code based on previous lines
of code’s results. This makes the code much more usable
and allows for many more scenarios to be solved by the
program. Finally flow control will allow the programmer to
write less code as the flow control can allow for the
same code to be reused in a loop till X happens for
an example. If less than 25, repeat. The flow control will
reuse the same line of code or lines of code till 25
has been met. Flow control and functions are important concepts
in programming that enable developers to create complex and
flexible applications. In a weather forecasting application, flow
control is used to determine how the program behaves in
different scenarios. For example, if the user enters an invalid
location, the application would display an error message and
prompt the user to try again. Functions break down the
program into smaller, reusable pieces that can be combined to
perform specific tasks, such as formatting the data returned
from the API or generating activity recommendations based on
weather conditions. By using flow control and functions, developers
can create applications that are easy to modify and extend.
This means that new functions can be added, or existing
ones modified without having to change the main function's
code. For instance, if the application needs to support multiple
weather APIs or display more detailed weather information,
developers can modify the existing functions or add new ones
to achieve this.Flow control and functions are powerful tools
that enable developers to create flexible, maintainable, and extensible
applications. They allow developers to create applications that can
adapt to changing requirements and provide a better user
experience. In the case of a weather forecasting application,
flow control, and functions would be used to handle user
input, query the weather API for data, and display the results,
as well as generate actionable recommendations based on the
weather conditions. An example application is one where students
are being evaluated for admission to a university; various
conditions need to be checked such as test scores, GPA,
statement-of-purpose, financial status - and flow control statements
are required to decide whether a student can be granted
admission or not and also whether the student can be
considered eligible for financial aid. Also, there are limited
seats available in each course and there is a budget for
financial aid, so loops come in handy to grant admission to
students as long as seats are available and as long as the
aid budget is not exhausted. Flow control also comes into
play if a student declines an admission, and an alternate
student needs to be chosen for admission from the waiting
list. For code that is repeated (e.g. the same logic applies
with slight variations for domestic, in-state, out-of-state and
international students), moving the concerned code to a function
allows us to avoid repeating very similar code in multiple
places. Without flow control, it would be impossible to write
software to check various conditions and change execution paths
based on these, hence these are fundamental to C# (and any
programming language). Flow control in an application is used
to help program execution take various paths. Often times when
the flow control sends the program execution a certain way
different functions could be called. It is the functions in
your program that will not only be called based on flow
control but will be called and within them have flow control
and even more functions able to be called.
For example, lets say you have a web based account
registration application. Users will be required to fill out certain
fields such as first name, last name, email and phone number.
A function be called once the user hits the submit button
in order to check the information. Inside the function could
be flow control such as "if" statements to check that a
value was entered and that it was a valid value. The first
step to any language is syntax, but there is a lot more
to building software system solutions than just building a system
that compiles and runs. (More on performance in future weeks).
Most of us will work for an organization where we are
part of a development team. The ability to adhere to standards
for code development, data security/integrity, and performance will
at the top of the priority list for any development project.
Thus, the introduction of style guides. A style guide is
typically a document that has rules and guidelines about how
to write code. This is typically language-specific but there are
organizational style and standards that will be applied across
all languages and development platforms. C# has several types
of flow control constructs that can be found in other
programming languages, such as loops, switches, and conditionals
but it also has some features and syntax for flow control.
A good example is "yield return" statement that allows creation
of iterators that can repeat a group of values over and
over making it easier for working with large data sets. It
also has the "lock" statement that allows multithreading, creating
critical sections of code that can be used by one thread
at a time. It helps prevents race conditions and synchronization
issues. In Conclusion C# as a lot of the same flow control
that other languages have. And do not let me forget to
reiterate that it is one of the very important languages used
to write Operating system like IOS, Android, Linux, Windows
and Mac OS. It is a trusted language used for generations
of platforms that have come and gone over the many years.
That is what makes it a great tool, is its unique features
and Syntax to managing program flow and creating efficient
and effective code. The Control Flow Statements in C# are
the statements that Alter the Flow of Program Execution and
provide better control to the programmer on the flow of
execution. The Control Flow Statements are useful to write
better and more complex programs. A program executes from
top to bottom except when we use control statements. We
can control the order of execution of the program, based on
logic and values.
Students also viewed