The code you want to reproduce in App Inventor was produced in a different programming language. Where does that programming example come from?
To help you understand how App Inventor 2 Blocks work, here are some resources to help you learn to use the AI2 tools A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook
http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
What App Inventor 2 blocks have you tried? You can post an image of your Blocks here in the Forum and someone probably will provide specific advice.