Sometimes you will want everything in the foreground and background in focus. Sometimes you will want a subject in the foreground to be in focus while keeping a busy background out of focus. When you make this type of decision, you are considering Depth of Field (the distance in front and behind of the subject that is acceptably in focus).

The f-stop controls this effect with blurring most apparent at large apertures. Small apetures keep more things in focus than larger apertures. For example f/16 will keep most if not all of the subject in focus. f/1.8 will focus on just the immediate foreground leaving the rest of the image blurred.