Git Product home page Git Product logo

no_body_for_loop's Introduction

For loop without a body

This is a very simple program where it takes three (3) numbers from the user as an input and finds the maximum one out of the three. It is not something complicated, but they way it is done is using a for loop without a body!

How this came around?

I was in class in high school and we had C++ lesson. The teacher wanted us to create a program that will ask the user for three numbers as input and then calculate the maximum one out of the three. The initial solution the teacher wanted us was to construct, was a program with three if...else conditions. While I did that, I also implemented a way to do it using a vector and calling the build-in function max_element of the vector. However, when I bragged about this, it was suggested to me to try and find a quicker way through a for loop without a body. This is the program that is in this repo. Due to the simplicity of the code, I based the results on Visual Studio's analytics to find out details on function calls and lines of code. The table below shows how the various implementations faired:

Description | If...Else | Vector | for loop (no body) :---:|:---:|:---: Lines of code | 23 | 17 | 12 Function calls | 66 | 617 | 66

From the results above, you can see that the for loop without the body has the least lines of code and the smallest number of function calls (albeit is the same as the If...Else program).

License

This project is licensed under the MIT license.

no_body_for_loop's People

Contributors

kyriakos-2004 avatar

Watchers

 avatar

Forkers

thefallen27

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.