Wolfram Cloud (Mathematica) Demo: While and For Loops

preview_player
Показать описание
In this video we look at While and For loops in Mathematica (Wolfram Cloud). The key to understanding the notation is to realize that While is a method with two arguments -- a condition and statements -- separated by a comma. While[condition, statements] If statements consists of multiple statements, then those statements are separated by semicolons. The for loop is similarly a method this time with four arguments. For[initialization, condition, incrementing, statements]. Again the last argument may consist of individual statements separated by semicolons. The particular example running through this video uses the RandomChoice method to obtain a random number between 1 and 10. We include some string-variable concatenation using the Print, StringForm, and ToString methods. In the last example we use AppendTo to push the random numbers generated onto a list.
Рекомендации по теме