New Posts

This commit is contained in:
Brandon Rozek 2021-08-27 22:03:42 -04:00
parent b8b4894bb4
commit 91ecc135fa
2 changed files with 71 additions and 0 deletions

View file

@ -0,0 +1,26 @@
---
title: "Do-While Loop in Other Languages"
date: 2021-08-27T21:50:02-04:00
draft: false
tags: []
math: false
---
Some languages like C, C++, and Java have a concept of a Do-While loop which normally look like the following:
```
do {
statements;
} while(condition);
```
This would ensure that your group of statements at least run once and then continue while the condition is still met. If you're used to that pattern, then it can be annoying when you switch to another language like Python and find that it doesn't exist. To replicate this behavior, its as simple as adding an extra variable.
```python
first_run = True
while condition or first_run:
first_run = False
statements
```