If the expression returns TRUE, then the program will execute all code between the brackets. The figure below shows the conditional flow chart of an if-statement.:Ĭondition should be an expression that evaluates to TRUE or FALSE. An if statement is a good choice here because it allows us to control the code execution depending on the conditional. An if statement tells the interpreter to run a line of code if a condition returns TRUE. We can use an if statement to write a program that prints out the winning team. We can visualize this scenario through a tree chart:Īs we can see in the tree chart, there are only two possible outcomes. Note: we'll be using fictitious data in this post. Let's say we're watching a match that decides which team makes the playoffs. We assume some familiarity with basic data structures, arithmetic operations, and comparison operators. In this tutorial, we teach you how to use control structures by building a simple algorithm that tells you who won or lost a soccer match. The course is a continuation of the R Fundamentals course and includes a certificate of completion. This tutorial is based on part of our newly released Intermediate R course.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |